package com.dora.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * RabbitMQ 应用程序
 *
 * @author Clarence
 * @date 2024/03/03
 */
@Slf4j
@SpringBootApplication
public class RabbitMQApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(RabbitMQApplication.class, args);
        String port = context.getEnvironment().getProperty("server.port");
        log.info("RabbitMq启动成功，点击访问：http://localhost:{}/demo", port);
    }

    /**
     * 目的解决：A cookie header was received警告
     */
    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
        return tomcatServletWebServerFactory ->
                tomcatServletWebServerFactory.addContextCustomizers((TomcatContextCustomizer)
                        context -> {
                            context.setCookieProcessor(new LegacyCookieProcessor());
                        });
    }


}
